﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;


namespace Nivdal.HE
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Status = "301 Moved Permanently";
            Response.AddHeader("Location", "../Default.aspx");
            //if (HttpContext.Current.User.Identity.IsAuthenticated)
            //    Response.Redirect("~/TeamHomePage.aspx");

            //GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            ////this.NumberOfOnlineUsersLabel.Text = (GND.ReadNivdalIntData("Nivdal_GetNumberOfOnlineUsers")).ToString();
            //this.NumberOfOnlineUsersLabel.Text = Application["ActiveUsers"].ToString();
            //this.NumberOfActiveUsersLabel.Text = NumOfActiveUsers().ToString();

            //UsersCountPanel.Direction = ContentDirection.RightToLeft;
            //WelcomeTextPanel.Direction = ContentDirection.RightToLeft;
            ////PlayFreePanel.Direction = ContentDirection.RightToLeft;
            //(LoginView1.FindControl("LoginPanel") as Panel).Direction = ContentDirection.RightToLeft;
        
            //if ((!IsPostBack) && (Request.UrlReferrer != null))
            //    GND.ExecNivdalSQL("Source", "Nivdal_AddTrafficSource", Request.UrlReferrer.OriginalString);
        }

        protected int NumOfActiveUsers()
        {

            string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            System.Data.SqlClient.SqlConnection
            strConnection = new System.Data.SqlClient.SqlConnection(conn);
            string StrSQL = "Nivdal_GetNumberOfActiveUsers";
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(StrSQL, strConnection);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ROWCOUNT", System.Data.SqlDbType.Int, 0));
            cmd.Parameters["@ROWCOUNT"].Direction = ParameterDirection.ReturnValue;

            strConnection.Open();
            try
            {

                cmd.ExecuteNonQuery();
                return (int)(cmd.Parameters["@ROWCOUNT"].Value);

            }
            catch (Exception SQLDBException)
            {
                Response.Write(SQLDBException.Message);
                //Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type=\"text/javascript\">alert('" + SQLDBException.Message + "');</script>");
                return 0;

            }

            finally
            {

                strConnection.Close();
            }

        }

        protected void LoggedIn(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string UserId;
            string TeamId;
            UserId = GND.ReturnUserId();
            Session["UserId"] = UserId;
            Session["UserName"] = GND.ReadNivdalStringData("UserId", "Nivdal_GetUserNameById", UserId);
            TeamId = GND.ReadNivdalIntData("@UserId", "Nivdal_GetTeamIdByUserId", UserId);
            Session["TeamId"] = TeamId;
        }
    }
}